/*
btContents = {
    'all' : [
        '电池',
        '衣架',
    ],
    '1' : [
        "bt1 detail1",
        "bt1 detail2",
        "bt1 detail3",
    ],
    '2' : [
        "bt2 detail1",
        "bt2 detail2",
        "bt2 detail3",
        "bt2 detail4",
        "bt2 detail5",
    ]
}
*/
btContents = {}

function parserCsv() {
    l = "整车,电机,车架,衣架,反射器、照明和鸣号装置,电气装置,电池,国际国外标准";
    $.ajax({
        type: 'get',
        url: 'mobile.csv',
        async: false,
        success: function(content){
            tmp = content.split("\r\n");
            ret = {};
            for(i=1; i<tmp.length; i++){
                line = tmp[i];
                lineArr = line.split(',');
                for(j=0; j<lineArr.length; j++) {
                    if(j == 0) {
                        type = 'all';
                    } else {
                        type = j;
                    }
                    lineArr[j] = lineArr[j].replace('"', '');
                    if(lineArr[j] && lineArr[j] != '') {
                        if(!ret[type]){ 
                            ret[type] = [];
                        }
                        ret[type].push(lineArr[j]);
                    }
                }
            }
            btContents = ret;
        }
    });
}

function init() {
    parserCsv();
    console.log(btContents);
    $('#main_view').text('');
    content = '<img src="/mobile/all.jpg"></img>';
    $('#main_view').append(content);
    showList('all');
}

breakFlag = false;

function breakFn() {
    init();
    if(!breakFlag) {
        breakFlag = true;
        appendYijia();
        appendDianchi();
    } else {
        breakFlag = false;
    }
}

function appendDianchi() {
    style = 'left:212px;top:153px';
    content = '<img class="img-arror" src="/mobile/arror.png" style="' + style + '"></img>';
    $('#main_view').append(content);
    style = 'left:52px;top:54px';
    content = '<img class="img-part"  src="/mobile/dianchi.png" style="' + style + '"></img>';
    $('#main_view').append(content);
}

function appendYijia() {
    style = 'left:150px;top:204px';
    content = '<img class="img-arror" src="/mobile/arror.png" style="' + style + '"></img>';
    $('#main_view').append(content);
    style = 'left:-2px;top:193px';
    content = '<img class="img-part"  src="/mobile/yijia.png" style="' + style + '"></img>';
    $('#main_view').append(content);
    showList('all');
}

function showList(type) {
    content = "<ul>";
    for(var i=0;i<btContents[type].length;i++) {
        content = content + "<li>" + btContents[type][i] + "</li>";
    }
    $('#c_description').text('');
    content += "<div class='desc_detail'><a href='#' onclick='showDetail()'>详情</a></div>";
    console.log(content);
    $('#c_description').append(content);
}

function btFn(type) {
    $('#main_view').text('');
    content = '<img src="/mobile/all.jpg"></img>';
    $('#main_view').append(content);
    if(type == 1) {
        appendDianchi() 
    } else if(type == 2) {
        appendYijia(); 
    }
    showList(type);
}

function showDetail() {
    $('#c_description').text('');
    content = '<iframe src="http://192.168.99.100:8001/a111.pdf" style="width:100%;height:98%"></iframe>';
    $('#c_description').append(content);
}
